package Gamedemo;

import java.util.ArrayList;
import java.util.Collection;

public class Team extends player{
    player[] team;
    public Team(player p,int i) //创建队伍
    {
        player[] team=new player[i];
        team[0]=p;
        this.team=team;
    }

    public void add(player p)//加人
    {
        try {
            for (int i=0;i<team.length;i++) {
                if (team[i].id == p.id) {
                    System.out.println("已入队，请勿重复申请");
                    return;
                }
            }
        }catch (NullPointerException e)
        {

        }
            for (int i = 0; i < team.length; i++) {
                if (team[i] == null) {
                    team[i] = p;
                    System.out.println(p.name+"成功入队");
                    return;
                }
            }
            for (int i = 0; i < team.length; i++) {
                if (team[i] != p) {
                    if (i == team.length - 1) {
                        System.out.println("队伍已满");
                        return;
                    }
                }
            }

    }

    public void remove(int p)//踢人
    {
        try {
            for (int i = 0; i < team.length; i++) {
                if (team[i].id!=p & i == team.length - 1) {
                    System.out.println("队伍中没有此人");
                    return;
                }
            }
        }catch (NullPointerException e)
        {
        }
        try {
            for (int i = 0; i < team.length; i++) {
                if (team[i].id==p) {
                    team[i] = null;
                    System.out.println(p + "已踢出队伍");
                }
            }
    }catch (NullPointerException e)
    {
    }
    }

    public int Battlevalue()
    {
        int agg=0;
        for (int i=0;i<team.length;i++)
        {
            if (team[i]!=null)
            {
                agg=agg+team[i].aggressivity;
            }
        }
        return agg;
    }
    public void att()
    {
        for (int i=0;i<team.length;i++) {
            team[i].Attack();
        }
    }
}
